package com.woniuxy.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.entity.GoodsFocus;
import com.woniuxy.entity.GoodsManagement;
import com.woniuxy.service.GoodsFocusService;
import com.woniuxy.utils.Result;

@Controller
@RequestMapping("/goodsfocus")
public class GoodsFocusController {
	
	@Autowired
	private GoodsFocusService goodsFocusService;
	
	//查询所有产品
	@ResponseBody
	@RequestMapping("/all")
	public List<GoodsFocus> goodsFocus(){
		return goodsFocusService.findGoodsFocus();
	}
	
	
	// 通过gfid查询当前行的数据
	@ResponseBody
	@RequestMapping("/searchData")
	public GoodsFocus searchData(int gfid) {
		return goodsFocusService.findGoodsByGfid(gfid);
	}
	
	
	// 通过gfid修改关注状态
	@ResponseBody
	@RequestMapping("/changeStatus")
	public Result<Object> changeStatus(int gfid,int status) {
		Result<Object> result = new Result<>();
		if (status==1) {
			int result0 = goodsFocusService.modifyStatusByGfidZero(gfid);
			if (result0 != 0) {
				result.setStatus(result.SUCCESS);
				result.setMessage("已取消关注");
			} else {
				result.setStatus(result.ERROR);
				result.setMessage("已取消关注失败");
			}
		} else {
			int result1 = goodsFocusService.modifyStatusByGfidOne(gfid);
			if (result1 != 0) {
				result.setStatus(result.SUCCESS);
				result.setMessage("关注成功");
			} else {
				result.setStatus(result.ERROR);
				result.setMessage("关注失败");
			}
		}
		return result;
	}
	
	
	// 通过gfid删除当前数据
	@ResponseBody
	@RequestMapping("/deleteData")
	public Result<Object> changeStatus(int gfid) {
		Result<Object> result = new Result<>();
		int delResult = goodsFocusService.deleteDataByGfid(gfid);
		if (delResult != 0) {
			result.setStatus(result.SUCCESS);
			result.setMessage("数据删除成功");
		} else {
			result.setStatus(result.ERROR);
			result.setMessage("数据删除成功");
		}
		return result;
	}
	
	
	//	根据状态查询selectStatusByOne
	@ResponseBody
	@RequestMapping("/selectStatus")
	public List<GoodsFocus> selectStatusByOne(int status){
		System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++123");
		return goodsFocusService.selectStatusByOne(status);
	}
}
